Fix #686: Add warning for bad line directives#687
Conversation
Co-authored-by: Daniel Marjamäki <daniel.marjamaki@gmail.com>
Co-authored-by: Daniel Marjamäki <daniel.marjamaki@gmail.com>
| try { | ||
| line = std::stoul(ppTok->str()); | ||
| } catch (...) { | ||
| line = std::numeric_limits<unsigned long>::max(); |
There was a problem hiding this comment.
this value might not work well.. it means tokens might get line number 0 which cppcheck interprets as "no line".
I suggest that the value passed in the lineDirective call will be 1. After reporting the error message.. change it to 1?
There was a problem hiding this comment.
Actually it might be better that we just ignore the line number and use the current one when it's out of range, what do you think?
There was a problem hiding this comment.
Or just discard the line directive entirely.
There was a problem hiding this comment.
I would be fine with both those options.
There was a problem hiding this comment.
I've changed it to just use the maximum possible line number, I think that's alright. It's guaranteed to always be representable, and it's also the most lenient option in terms of conditional support.
readfilenow takes aDUIwith information about which standard to use, which is needed to determine if a warning should be issued or not.preprocessnow also includes outputs frommakeTokenListswhich callsreadfile. Some tests had to be fixed to have an ending newline because of this in order to pass.